import { app_request as request } from "@/utils/http";
//获取spu分页列表

export interface spuPageListType {
    records: recordsListType;
    total: number;
    size: number;
    current: number;
    searchCount: boolean;
    pages: number;
}
export type recordsListType = recordsItemType[]
export interface recordsItemType {
    id?: number;
    spuName: string;
    description: string;
    category3Id: number;
    tmId: number | undefined;
    spuSaleAttrList?: any | spuSaleAttrListType;
    spuImageList?: any | spuImageListType;
}
// 获取分页列表
export function getspuPageList(page: number, limit: number, category3Id: number) {
    return request.get<null, spuPageListType>(`/admin/product/${page}/${limit}`, { params: { category3Id } })
}
// 新增新的spu
// 销售属性列表
export interface spuSaleAttrItemType {
    id?: number
    spuId?: number
    baseSaleAttrId: number
    saleAttrName: string
    isHidden: boolean
    // 用于新增sku数据的整合id
    baseIdItemid?: string
    spuSaleAttrValueList: spuSaleAttrValueListType
}
export type spuSaleAttrListType = spuSaleAttrItemType[]
// 销售属性值列表
export interface spuSaleAttrValueItemType {
    id?: number
    isChecked?: number
    spuId?: number
    baseSaleAttrId: number
    saleAttrName: string
    saleAttrValueName: string

}
export type spuSaleAttrValueListType = spuSaleAttrValueItemType[]

// 图片列表接口
export interface spuImageItemType {
    id?: number;
    spuId?: number;
    imgName: string
    imgUrl: string
    ischange?: boolean
    isDefault?: boolean
}
export type spuImageListType = spuImageItemType[]
export function addSpuInfo(spuindo: recordsItemType) {
    return request.post<null, null>(`/admin/product/saveSpuInfo`, spuindo)
}

// 请求照片墙函数
export function reqImageList(spuId: number) {
    return request.get<null, spuImageListType>(`/admin/product/spuImageList/${spuId}`)
}

// 请求底部销售属性列表
export function reqAttrsList(spuId: number) {
    return request.get<null, spuSaleAttrListType>(`/admin/product/spuSaleAttrList/${spuId}`)
}
export function updateSpuInfo(spuindo: recordsItemType) {
    return request.post<null, null>(`/admin/product/updateSpuInfo`, spuindo)
}
